package com.zhisheng.gufei.produce.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.zhisheng.core.dao.impl.BaseDaoHibernate;
import com.zhisheng.core.page.Page;
import com.zhisheng.gufei.produce.dao.DeclarationDao;
import com.zhisheng.gufei.produce.entity.Declaration;

/**
 * @author xgye
 *
 */
@Repository("declarationDao")
public class DeclarationDaoHibernate extends BaseDaoHibernate<Declaration, Integer> implements
		DeclarationDao {

	public void require(Declaration dec) {
		getHibernateTemplate().save(dec);

	}

	public Declaration saveDeclaration(Declaration dec) {
	    getHibernateTemplate().save(dec);
	    return dec;
	}

	public List<Declaration> getDeclarationByCity(String areaCode) {
		return (List<Declaration>) findByHql("from Declaration dec where dec.areaCode = " + areaCode);
	}

	public Declaration getDeclarationById(Integer id) {
		return (Declaration) findByHql("from Declaration dec where dec.id = " + id).get(0);
	}

    public List<Declaration> getAllDeclaration() {
        return findAll();
    }

    public void removeDeclarationById(Integer id) {
        delete(id.toString());
    }
    
    
    public void getAuditPage(Page<Declaration> page,Integer audit){
    	Map<String,Object> params = new HashMap<String, Object>();
    	params.put("s", audit);
    	findPageByHql("from Declaration dec where dec.status=:s", params, page);
    }
    
    @Override
    public void getCheckedPage(Page<Declaration> page, String auditor) {
    	Map<String,Object> params = new HashMap<String, Object>();
    	params.put("auditor", auditor);
    	findPageByHql("from Audit a where a.auditor = :auditor", params, page);  	
    }

}
